package com.letoken.platform.repo.app.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.app.po.VideoRedEnvelope;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
import java.util.Set;

public interface VideoRedEnvelopesMapper extends BaseMapper<VideoRedEnvelope> {


    @Select("select video_id,created_date, created_time from video_red_envelopes where userid = #{userid} and created_date = current_date() and type = 1 order by created_date, created_time desc")
    List<VideoRedEnvelope> selectListByUserId(Integer userid);

    @Select("select sum(money) from video_red_envelopes where type = 1 and created_date = current_date();\n")
    BigDecimal sumTodayTotalAmount();

    @Select("select * from video_red_envelopes where id = #{id} for update")
    VideoRedEnvelope selectForUpdate(Integer id);

    @Select("select userid from video_red_envelopes where client_device_code = #{clientDeviceCode} and created_date = current_date() group by userid")
//    List<VideoRedEnvelope> selectList(@Param("userid") Integer userid, @Param("clientDeviceCode") String clientDeviceCode, @Param("createdDate") LocalDate createdDate);
    List<Integer> selectUserIds(String clientDeviceCode);

    @Select("select id from video_red_envelopes where client_device_code != #{clientDeviceCode} and userid = #{userid} and created_date = current_date() and status = 2 limit 1")
    Integer selectOtherDeviceRecord(@Param("userid") Integer userid, @Param("clientDeviceCode") String clientDeviceCode);
}
